/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package hangmangame;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Joana
 */
public class HangManFrame extends javax.swing.JFrame {

    HangManFrameView view;
    /**
     * Creates new form HangManFrame
     */
    public HangManFrame() {
        initComponents();
    }
    
    public HangManFrame(HangManFrameView view) {
        this();
        this.view = view;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        exitBtn = new javax.swing.JButton();
        newBtn = new javax.swing.JButton();
        gameArea = new javax.swing.JPanel();
        wordLabel = new javax.swing.JLabel();
        answereLabel = new javax.swing.JLabel();
        guessLabel = new javax.swing.JLabel();
        imageHangMan = new javax.swing.JLabel();
        playResultLabel = new javax.swing.JLabel();
        resultLabel = new javax.swing.JLabel();
        guessField = new javax.swing.JTextField();
        guessBtn = new javax.swing.JButton();
        MainMenu = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        menuItemExit = new javax.swing.JMenuItem();
        gameMenu = new javax.swing.JMenu();
        menuItemNew = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setPreferredSize(new java.awt.Dimension(720, 500));

        exitBtn.setText("Exit Game");
        exitBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitBtnActionPerformed(evt);
            }
        });

        newBtn.setText("New Game");
        newBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newBtnActionPerformed(evt);
            }
        });

        gameArea.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Hangman Game", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 14))); // NOI18N

        wordLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        wordLabel.setText("Word");

        answereLabel.setText("Guess me");

        guessLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        guessLabel.setText("Guess: ");

        imageHangMan.setText("Loading image...");

        playResultLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        playResultLabel.setText("----");

        resultLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        resultLabel.setText("----");

        guessBtn.setText("Guess");
        guessBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                guessBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout gameAreaLayout = new javax.swing.GroupLayout(gameArea);
        gameArea.setLayout(gameAreaLayout);
        gameAreaLayout.setHorizontalGroup(
            gameAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gameAreaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(gameAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(gameAreaLayout.createSequentialGroup()
                        .addGroup(gameAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(answereLabel)
                            .addComponent(guessLabel))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, gameAreaLayout.createSequentialGroup()
                        .addComponent(wordLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(imageHangMan)
                        .addGap(209, 209, 209))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, gameAreaLayout.createSequentialGroup()
                        .addComponent(guessField, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(guessBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(gameAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(playResultLabel)
                            .addComponent(resultLabel))
                        .addGap(273, 273, 273))))
        );
        gameAreaLayout.setVerticalGroup(
            gameAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gameAreaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(gameAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(wordLabel)
                    .addComponent(imageHangMan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(answereLabel)
                .addGap(18, 18, 18)
                .addComponent(guessLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gameAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(guessField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(gameAreaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(guessBtn)
                        .addComponent(resultLabel)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(playResultLabel)
                .addContainerGap(56, Short.MAX_VALUE))
        );

        fileMenu.setText("File");

        menuItemExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
        menuItemExit.setText("Exit");
        menuItemExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemExitActionPerformed(evt);
            }
        });
        fileMenu.add(menuItemExit);

        MainMenu.add(fileMenu);

        gameMenu.setText("Game");

        menuItemNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        menuItemNew.setText("New Game");
        menuItemNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemNewActionPerformed(evt);
            }
        });
        gameMenu.add(menuItemNew);

        MainMenu.add(gameMenu);

        setJMenuBar(MainMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 526, Short.MAX_VALUE)
                        .addComponent(newBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(exitBtn))
                    .addComponent(gameArea, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(gameArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(newBtn)
                    .addComponent(exitBtn))
                .addContainerGap(94, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menuItemNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemNewActionPerformed
        this.view.resetGame();
    }//GEN-LAST:event_menuItemNewActionPerformed

    private void newBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBtnActionPerformed
        this.view.resetGame();
    }//GEN-LAST:event_newBtnActionPerformed

    private void exitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitBtnActionPerformed
        this.dispose();
    }//GEN-LAST:event_exitBtnActionPerformed

    private void menuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemExitActionPerformed
        this.dispose();
    }//GEN-LAST:event_menuItemExitActionPerformed

    private void guessBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guessBtnActionPerformed
        this.view.checkStatus();
    }//GEN-LAST:event_guessBtnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HangManFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HangManFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HangManFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HangManFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new HangManFrame().setVisible(true);
            }
        });
    }

    public JLabel getAnswereLabel() {
        return answereLabel;
    }

    public JLabel getGuessLabel() {
        return guessLabel;
    }

    public JLabel getResultLabel() {
        return resultLabel;
    }

    public JLabel getPlayResultLabel() {
        return playResultLabel;
    }

    public JTextField getGuessField() {
        return guessField;
    }

    public JLabel getImageHangMan() {
        return imageHangMan;
    }

    public void setImageHangMan(JLabel imageHangMan) {
        this.imageHangMan = imageHangMan;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar MainMenu;
    private javax.swing.JLabel answereLabel;
    private javax.swing.JButton exitBtn;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JPanel gameArea;
    private javax.swing.JMenu gameMenu;
    private javax.swing.JButton guessBtn;
    private javax.swing.JTextField guessField;
    private javax.swing.JLabel guessLabel;
    private javax.swing.JLabel imageHangMan;
    private javax.swing.JMenuItem menuItemExit;
    private javax.swing.JMenuItem menuItemNew;
    private javax.swing.JButton newBtn;
    private javax.swing.JLabel playResultLabel;
    private javax.swing.JLabel resultLabel;
    private javax.swing.JLabel wordLabel;
    // End of variables declaration//GEN-END:variables
}
